package main

import (
	"encoding/json"
	"jlpay-sdk-go/pkg/jlpay/demo"
	"jlpay-sdk-go/pkg/jlpay/models/ledger"
	ledger2 "jlpay-sdk-go/pkg/jlpay/services/ledger"
	"jlpay-sdk-go/pkg/jlpay/utils"
)

// 商户分账开通示例
func merchRevOpenDemo() {
	config := demo.CreateDemoConfig()
	merchconfService := ledger2.NewMerchconfService(config)

	// 构建请求参数
	requestData := map[string]interface{}{
		"org_code":                "50720711",
		"merch_type":              "1",
		"mch_id":                  "849581183510017",
		"license_number":          "91330108MAB555NP6U",
		"license_name":            "深圳市泰思能源有限公司",
		"license_address":         "深圳市南山区科技南路105号",
		"license_begin_date":      "2024-01-01",
		"license_end_date":        "2024-12-31",
		"license_front_source_id": "jlpay/2024-08-30/e22bc590f4131418483626fded04f3362.png",
		"legal_name":              "张三",
		"legal_number":            "110101199001011234",
		"legal_begin_date":        "2020-01-01",
		"legal_end_date":          "2030-01-01",
		"legal_front_source_id":   "jlpay/2024-08-30/e22bc590f433412131326fded04f3362.png",
		"legal_back_source_id":    "jlpay/2024-08-30/e22bc590f4311418483626fded04f3362.png",
		"mobile":                  "13800138000",
		"bank_card_no":            "6226001234567890",
		"bank_card_name":          "张三",
		"bank_code":               "308",
		"bank_name":               "中国建设银行股份有限公司",
		"bank_branch_code":        "105584000370",
		"bank_branch_name":        "中国建设银行股份有限公司深圳罗湖支行",
	}

	request := ledger.NewMerchRevOpenRequest()
	request.SetRawRequestMap(requestData)

	// 序列化请求数据并打印
	requestJSON, _ := json.Marshal(requestData)
	utils.Debugf("商户分账开通请求数据: %s", string(requestJSON))

	// 发送请求
	response, err := merchconfService.OpenMerchRev(request)
	if err != nil {
		utils.Errorf("商户分账开通请求失败: %v", err)
		return
	}

	// 处理响应 - 使用BaseResponse接口的HandleResponse方法
	response.HandleResponse("商户分账开通")
}

func main() {
	// 设置日志级别为info，显示详细的调试信息
	utils.SetLogLevel("info")

	utils.Info("=============================")
	utils.Info("===== 商户分账开通示例 开始 =====")
	utils.Info("=============================")

	merchRevOpenDemo()

	utils.Info("=============================")
	utils.Info("===== 商户分账开通示例执行完毕 =====")
	utils.Info("=============================")
}
